package cn.tansanqinger.dao.sql.account;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tansanqinger.dao.sql.IUserSqlDao;
import cn.tansanqinger.pojo.User;

/**
 * 账号数据查询
 * @author C3H2
 * @time 2021.01
 */
@Repository
public class AccountSqlDaoImpl {
	
	@Autowired
	private IUserSqlDao accountSqlDao;
	
	//查询教师账号处于审核状态的账号数量
	public int selectTeacherCheckAmount() {
		QueryWrapper<User> qw = new QueryWrapper<User>();
		qw.lambda().eq(User::getIsactivate, 0);
		return accountSqlDao.selectCount(qw);
	}
	//查询账号处于举报状态的账号数量
	public int selectAccountReportAmount() {
		QueryWrapper<User> qw = new QueryWrapper<User>();
		qw.lambda().eq(User::getIsreport, 1);
		return accountSqlDao.selectCount(qw);
	}
	//查询账号处于申述状态的账号数量
	public int selectAccountSataeAmount() {
		QueryWrapper<User> qw = new QueryWrapper<User>();
		qw.lambda().eq(User::getIsstate, 1);
		return accountSqlDao.selectCount(qw);
	}
	//查询待处理知识点的数量
	public int selectPendingKnowledgeAmount() {
		return 0;
		
	}
	//查询有异议的知识点的数量
	public int selectObjectionableKnowledgeAmount() {
		return 0;
		
	}
	//查询待处理的新试题数量
	public int selectPendingTopicAmount() {
		return 0;
		
	}
	//查询待处理异议试题数量
	public int selectObjectionableTopicAmount() {
		return 0;
		
	}
	
	//查询教师数据
	public int selectTeacherAll() {
		QueryWrapper<User> qw = new QueryWrapper<User>();
		qw.lambda().eq(User::getJurisdiction, 1);
		return accountSqlDao.selectCount(qw);
		//return selectAddAmount(qw);
	}
	//查询学生数据
	public int selectStudentAll() {
		QueryWrapper<User> qw = new QueryWrapper<User>();
		qw.lambda().eq(User::getJurisdiction, 0);
		return accountSqlDao.selectCount(qw);//新修改方法，取代下面的方法
		//return selectAddAmount(qw);
	}
	
	public int[] selectAddAmount(QueryWrapper<User> qw) {
		int arr[] = new int[4];
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<User> list = accountSqlDao.selectList(qw);
		Long data = 0L;
		for (int i = 0; i < list.size(); i++) {
			Calendar calendar = Calendar.getInstance();
	        calendar.set(Calendar.HOUR_OF_DAY, 0);
	        calendar.set(Calendar.MINUTE, 0);
	        calendar.set(Calendar.SECOND, 0);
	        try {
	        	data = format.parse(list.get(i).getCreatetime()).getTime();
			} catch (Exception e) {}
	        if(data-calendar.getTimeInMillis()>0) {
	        	arr[0] ++;
	        	arr[1] ++;
	        	arr[2] ++;
	        	arr[3] ++;
	        	continue;
	        }
	        calendar.set(Calendar.DAY_OF_MONTH, 1);
	        if(data-calendar.getTimeInMillis()>0) {
	        	arr[1] ++;
	        	arr[2] ++;
	        	arr[3] ++;
	        	continue;
	        }
	        calendar.set(Calendar.MONTH, 0);
	        if (data-calendar.getTimeInMillis()>0) {
	        	arr[2] ++;
	        	arr[3] ++;
	        	continue;
			}
	        arr[3] ++;
		}
		return arr;
	}
	
	//查询本月浏览人数
	public int selectMonthBrowseAmount() {
		return 0;
		
	}
	//查询本年浏览人数
	public int selectYearBrowseAmount() {
		return 0;
		
	}
}
